/*
 * @lc app=leetcode.cn id=169 lang=csharp
 *
 * [169] 多数元素
 */

// @lc code=start
public class Solution {
    public int MajorityElement(int[] nums) {
        var num = nums.Length / 2;
        var dict = new Dictionary<int, int>();
        foreach (var n in nums)
        {
            if (dict.ContainsKey(n))
            {
                dict[n]++;
            }
            else
            {
                dict[n] = 1;
            }
            if (dict[n] > num)
            {
                return n;
            }
        }
        return 0;
    }
}
// @lc code=end

